<%@page import="net.sf.json.JSONObject"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/classes/DBHelper.class.jsp"%>
<%@ include file="/classes/CommonHelper.class.jsp"%>
<%
	//获取数据
	String qa_id = request.getParameter("qa_id");
	String answer = request.getParameter("answer");
	String answerTime = request.getParameter("answerTime");
	String status = request.getParameter("status");
	JSONObject result = new JSONObject();
	if (nullOrEmpty(qa_id)) {
		result.put("status", -1);
		result.put("msg", "参数错误");
		out.println(result);
		return;
	}
	if (nullOrEmpty(status)) {
		result.put("status", -1);
		result.put("msg", "请选择是否通过");
		out.println(result);
		return;
	}
	if (nullOrEmpty(answer)) {
		result.put("status", -1);
		if ("B".equals(status)) {
			result.put("msg", "请输入答复内容");
		} else if ("C".equals(status)) {
			result.put("msg", "请输入不通过理由");
		} else {
			result.put("msg", "不通过状态错误");
		}
		out.println(result);
		return;
	}
	if (nullOrEmpty(answerTime)) {
		answerTime = formatDate("yyyy-MM-dd HH:mm:ss", new Date());
	}
	//转换时间
	Date answer_time = null;
	try {
		answer_time = toDate("yyyy-MM-dd HH:mm:ss", answerTime);
	} catch (Exception e) {
		result.put("status", -1);
		result.put("msg", "时间格式错误");
		out.println(result);
		return;
	}

	String sql = "UPDATE APP_QA t SET t.answer = ? ,t.status = ? ,t.answer_time = to_date(?,'YYYY-MM-DD HH24:MI:SS'),t.answer_ip = ? WHERE t.qa_id = ?";
	int i = executeUpdate(sql, new Object[] { answer, status, answerTime, getIpAddr(request), qa_id });
	if (i >= 1) {
		result.put("status", 200);
		result.put("msg", "操作成功");
		out.println(result);
	} else {
		result.put("status", -1);
		result.put("msg", "操作失败");
		out.println(result);
	}
%>